﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Realms;
using Realms.Exceptions;

namespace TestRealm;

public partial class App : Application
{
    public static Realm? Realm { get; private set; }

    protected override void OnStartup(StartupEventArgs e)
    {
        var config = new RealmConfiguration(Environment.CurrentDirectory + "my.realm")
        {
        };
        Realm localRealm;
        try
        {
            localRealm = Realm.GetInstance(config);
            Realm = localRealm;
        }
        catch (RealmFileAccessErrorException ex)
        {
            Console.WriteLine($@"Error creating or opening the realm file. {ex.Message}");
        }
    }

    protected override void OnExit(ExitEventArgs e)
    {
        Realm?.Dispose();

        base.OnExit(e);
    }
}